package com.ruoyi.other.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.check.CheckEmptyUtil;
import com.ruoyi.other.domain.CityFareGlobalConfig;
import com.ruoyi.other.mapper.CityFareGlobalConfigMapper;
import com.ruoyi.other.service.ICityFareGlobalConfigService;
import com.ruoyi.other.vo.UpdateBanchVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 城市路费全局配置Service业务层处理
 *
 * @author ruoyi
 * @date 2025-04-16
 */
@Service
public class CityFareGlobalConfigServiceImpl implements ICityFareGlobalConfigService {
    @Autowired
    private CityFareGlobalConfigMapper cityFareGlobalConfigMapper;

    /**
     * 查询城市路费全局配置
     *
     * @param id 城市路费全局配置主键
     * @return 城市路费全局配置
     */
    @Override
    public CityFareGlobalConfig selectCityFareGlobalConfigById(Long id) {
        return cityFareGlobalConfigMapper.selectCityFareGlobalConfigById(id);
    }

    /**
     * 查询城市路费全局配置列表
     *
     * @param cityFareGlobalConfig 城市路费全局配置
     * @return 城市路费全局配置
     */
    @Override
    public List<CityFareGlobalConfig> selectCityFareGlobalConfigList(CityFareGlobalConfig cityFareGlobalConfig) {
        return cityFareGlobalConfigMapper.selectCityFareGlobalConfigList(cityFareGlobalConfig);
    }

    /**
     * 新增城市路费全局配置
     *
     * @param cityFareGlobalConfig 城市路费全局配置
     * @return 结果
     */
    @Override
    public int insertCityFareGlobalConfig(CityFareGlobalConfig cityFareGlobalConfig) {
        cityFareGlobalConfig.setCreateTime(DateUtils.getNowDate());
        return cityFareGlobalConfigMapper.insertCityFareGlobalConfig(cityFareGlobalConfig);
    }

    /**
     * 修改城市路费全局配置
     *
     * @param cityFareGlobalConfig 城市路费全局配置
     * @return 结果
     */
    @Override
    public int updateCityFareGlobalConfig(CityFareGlobalConfig cityFareGlobalConfig) {
        cityFareGlobalConfig.setUpdateTime(DateUtils.getNowDate());
        return cityFareGlobalConfigMapper.updateCityFareGlobalConfig(cityFareGlobalConfig);
    }

    /**
     * 批量删除城市路费全局配置
     *
     * @param ids 需要删除的城市路费全局配置主键
     * @return 结果
     */
    @Override
    public int deleteCityFareGlobalConfigByIds(Long[] ids) {
        return cityFareGlobalConfigMapper.deleteCityFareGlobalConfigByIds(ids);
    }

    /**
     * 删除城市路费全局配置信息
     *
     * @param id 城市路费全局配置主键
     * @return 结果
     */
    @Override
    public int deleteCityFareGlobalConfigById(Long id) {
        return cityFareGlobalConfigMapper.deleteCityFareGlobalConfigById(id);
    }

    @Transactional(rollbackFor = RuntimeException.class)
    @Override
    public int updateBanch(List<UpdateBanchVo> updateBanchVos) {
        if (!CheckEmptyUtil.isEmpty(updateBanchVos)) {
            for (UpdateBanchVo updateBanchVo : updateBanchVos) {
                if ("day_start_time".equals(updateBanchVo.getCode())) {
                    cityFareGlobalConfigMapper.updateValueByCode(updateBanchVo.getCode(), updateBanchVo.getValue());
                }
                if ("day_end_time".equals(updateBanchVo.getCode())) {
                    cityFareGlobalConfigMapper.updateValueByCode(updateBanchVo.getCode(), updateBanchVo.getValue());
                }
                if ("night_start_time".equals(updateBanchVo.getCode())) {
                    cityFareGlobalConfigMapper.updateValueByCode(updateBanchVo.getCode(), updateBanchVo.getValue());
                }
                if ("night_end_time".equals(updateBanchVo.getCode())) {
                    cityFareGlobalConfigMapper.updateValueByCode(updateBanchVo.getCode(), updateBanchVo.getValue());
                }
                if ("day_start_distance".equals(updateBanchVo.getCode())) {
                    cityFareGlobalConfigMapper.updateValueByCode(updateBanchVo.getCode(), updateBanchVo.getValue());
                }
                if ("day_start_price".equals(updateBanchVo.getCode())) {
                    cityFareGlobalConfigMapper.updateValueByCode(updateBanchVo.getCode(), updateBanchVo.getValue());
                }
                if ("day_pre_price".equals(updateBanchVo.getCode())) {
                    cityFareGlobalConfigMapper.updateValueByCode(updateBanchVo.getCode(), updateBanchVo.getValue());
                }
                if ("night_start_distance".equals(updateBanchVo.getCode())) {
                    cityFareGlobalConfigMapper.updateValueByCode(updateBanchVo.getCode(), updateBanchVo.getValue());
                }
                if ("night_start_price".equals(updateBanchVo.getCode())) {
                    cityFareGlobalConfigMapper.updateValueByCode(updateBanchVo.getCode(), updateBanchVo.getValue());
                }
                if ("night_pre_price".equals(updateBanchVo.getCode())) {
                    cityFareGlobalConfigMapper.updateValueByCode(updateBanchVo.getCode(), updateBanchVo.getValue());
                }
                if ("dummy_distance".equals(updateBanchVo.getCode())) {
                    cityFareGlobalConfigMapper.updateValueByCode(updateBanchVo.getCode(), updateBanchVo.getValue());
                }
                if ("free_fare_instructions".equals(updateBanchVo.getCode())) {
                    cityFareGlobalConfigMapper.updateValueByCode(updateBanchVo.getCode(), updateBanchVo.getValue());
                }

            }
        }
        return 1;
    }
}
